package com.hup.winHolderService.service.mouseMove;

import com.hup.utils.commons.hardware.HRobotJni;
import com.hup.utils.commons.hardware.MouseUtil;
import com.hup.winHolderService.model.action.MouseActionReq;

import java.awt.Point;

/**
 * 算法1
 * 问题:
 * .鼠标在屏幕边缘时, 有问题
 * .不能同时兼顾长短距离的移动
 *
 * @author hugan
 * @date 2023/10/13
 */
public class MouseMoveHandler1 implements MouseMoveHandler {

    /**
     * onMoveStart时, 鼠标的位置
     */
    private Point mouseDownLoc;
    /**
     * onMoveStart时, req传入的坐标
     */
    private int x0, y0;

    @Override
    public void onMoveStart(MouseActionReq req) {
        mouseDownLoc = MouseUtil.getLocation();
        x0 = req.getX();
        y0 = req.getY();
    }

    @Override
    public void onMove(MouseActionReq req) {
        HRobotJni.mouseMove((int) (mouseDownLoc.x + (req.getX() - x0) * req.getRatio()),
                (int) (mouseDownLoc.y + (req.getY() - y0) * req.getRatio()));
    }

}
